package com.nkzy.service.impl;

import com.nkzy.mapper.AddressMapper;
import com.nkzy.mapper.UserMapper;
import com.nkzy.pojo.Address;
import com.nkzy.pojo.User;
import com.nkzy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
//业务层完成业务逻辑，如果没有业务层，也必须有这一层
    @Autowired
    private UserMapper userMapper;

    @Autowired
    private AddressMapper addressMapper;

    @Override
    public int insertUser(User user) {
        return userMapper.insertUser(user);
    }

    @Override
    public int deleteUserById(Long id) {
        return userMapper.deleteUserById(id);
    }

    @Override
    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public User selectUserById(Long id) {
        return userMapper.selectUserById(id);
    }

    @Override
    public List<User> selectAllUsers() {
        return userMapper.selectAllUsers();
    }

    @Override
    public List<User> selectUsersByIds(List<Long> ids) {
        return userMapper.selectUsersByIds(ids);
    }

    @Override
    public void deleteAddressById(long l) {
        addressMapper.deleteAddressById(l);
    }

    @Override
    public void insertAddress(Address address) {
        addressMapper.insertAddress(address);
    }

    @Override
    public boolean selectAllAddress() {
        return addressMapper.getAllAddresses().size() > 0;
    }

    @Override
    public Address selectAddressById(long l) {
        return addressMapper.getAddressById(l);
    }
}